package com.hzy.fivepalace.admin.controller;

import com.hzy.fivepalace.admin.annotation.Login;
import com.hzy.fivepalace.admin.controller.base.BaseController;
import com.hzy.fivepalace.admin.service.CommonService;
import com.hzy.fivepalace.common.util.ResponseUtil;
import com.hzy.fivepalace.db.service.DtsRegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

@RestController
@RequestMapping("/admin/common")
@Validated
@Api(tags = "通用服务")
@Login
public class CommonController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(CommonController.class);

    @Resource
    private CommonService commonService;

    @Autowired
    private DtsRegionService regionService;

    /**
     * 用户下拉选列表
     *
     * @return
     */
    @PostMapping("/getUserSelectEntity")
    @ApiOperation(value = "用户下拉选列表")
    public Object getUserSelectEntity(@ApiParam(value = "手机号,必填,支持模糊查询", required = true) @RequestParam @NotBlank String phone) {

        return commonService.selectEntity(phone);
    }


    /**
     * 所有的区域列表
     *
     * @return
     */
    @PostMapping("getAllList")
    @ApiOperation(value = "所有的区域列表")
    public Object getGruopTree() {
        return ResponseUtil.ok(regionService.getAllList());
    }

}
